#-*- coding: utf8 -*-

from tutor.script import *
from tutor.plugin.maple import *

# meta information
meta(author       = 'Fábio Mendes',
     creationdate = datetime(2010, 10, 9),
     status       = 'testing',
     difficulty   = 'easy',
     time         = 10,
     itemtype     = 'test')

# seleciona pontos
x1 = oneof(0, 1, 2, 3, 5) * oneof(1, -1)
x2 = oneof(0, 1, 2, 3, 5) * oneof(1, -1)
y1 = oneof(0, 1, 2, 3, 5) * oneof(1, -1)
y2 = oneof(0, 1, 2, 3, 5) * oneof(1, -1)
x1, x2 = min(x1, x2), max(x1, x2)
y1, y2 = min(y1, y2), max(y1, y2) 
assert x1 != x2
assert y1 != y2

# define triangulo superior/inferior
upper_t = oneof(True, False)
P1 = (x1, y1)
P3 = (x2, y2)
if upper_t:
    P2 = (x1, y2)
else:
    P2 = (x2, y1)

question('Qual das integrais iteradas corresponde à integral \n\n'
         '$$\\iint_R\ dx\ dy\ f(x,y),$$\n\n'
         'onde $R$ é a região definida pelo triângulo de vértices $#1$, $#2$ e $#3$?', 
         P1, P2, P3)
multiplechoice()

res = '$\\int_{#1}^{#2} dx \\int_{#3}^{#4} dy\\ f(x, y)$'
res2 = '$\\int_{#1}^{#2} dy \\int_{#3}^{#4} dx\\ f(x, y)$'
reta = y1 + (x - x1) * (y2 - y1) / (x2 - x1)
reta2 = M.solve(y==reta, x)

# choice: (a)
xa = x1
xb = x2
if upper_t:
    ya = reta
    yb = y2
else:
    ya = y1
    yb = reta
choice(1, res, xa, xb, ya, yb)
explanation('Escolha correta!') 

# choice: (b)
xa, xb = x1, x2
if upper_t:
    ya = y1
    yb = reta
else:
    ya = reta
    yb = y2
choice(0.25, res, xa, xb, ya, yb)
explanation('Integrou sobre a região errada!') 

# choice: (c)
ya, yb = y1, y2
if upper_t:
    xa = x1
    xb = reta2
else:
    xa = reta2
    xb = x2
choice(0.25, res2, ya, yb, xa, xb)
explanation('Integrou sobre a região errada!') 

# choice: (d)
choice(0, res, x1, x2, y1, y2)
explanation('Integrou sobre um quadrado!') 

# choice: (e)
choice(0, res2, x1, x2, y1, y2)
explanation('Integrou sobre um quadrado!') 

end()